package com.smart.home.service.impl;

import com.smart.home.constant.HomeConstant;
import com.smart.home.constant.UsersConstant;
import com.smart.home.context.UserContext;
import com.smart.home.exception.BusinessException;
import com.smart.home.mapper.HomeMapper;
import com.smart.home.mapper.HomeMemberMapper;
import com.smart.home.service.HomeMemberService;
import com.smart.home.vo.HomeMembersVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


@Service
@Slf4j
public class HomeMemberServiceImpl implements HomeMemberService {

    @Autowired
    private HomeMemberMapper homeMemberMapper;
    @Autowired
    private HomeMapper homeMapper;

    @Override
    public List<HomeMembersVO> queryHomeMemberInfo(Long homeId) {
        Long userId = UserContext.getUserId();
        Long UseId = homeMapper.getIdByHomeName(homeId);

        log.info("用户id:{},{}",userId,UseId);

        //先验证这个id是否是这个家庭的
        if (!userId.equals(UseId)){
            throw new BusinessException(HomeConstant.USER_NOT_IN_HOME);
        }

        List<HomeMembersVO> homeMembersVOs = homeMemberMapper.queryHomeMemberInfo(homeId);
        return homeMembersVOs;
    }




}
